package com.jzo2o.customer.controller.consumer;


import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.ArrayList;

@RestController("AddressBookController")
@RequestMapping("/consumer/address-book")
@Api(tags = "地址 - 地址相关接口")
public class AddressBookController {


    @Resource
    IAddressBookService addressBookService;


    /**
     * @description: 添加地址簿
     * @author: xushuaihang
     * @Date: 2024/8/18 21:05
     * @param:
     * @param addressBookUpsertReqDTO
     * @return: void
    **/
    @PostMapping
    @ApiOperation("添加地址簿")
    public void addAddress(@RequestBody AddressBookUpsertReqDTO addressBookUpsertReqDTO) throws ParseException {

        addressBookService.addAddress(addressBookUpsertReqDTO);
    }


    /**
     * @param addressBookPageQueryReqDTO
     * @description: 地址薄分页查询接口
     * @author: xushuaihang
     * @Date: 2024/8/19 8:54
     * @param:
     * @return: com.jzo2o.common.model.PageResult<com.jzo2o.customer.model.domain.AddressBook>
     **/
    @GetMapping("/page")
    @ApiOperation("分页地址簿")
    public PageResult<AddressBookResDTO> addressList(AddressBookPageQueryReqDTO addressBookPageQueryReqDTO

    ) {

        return addressBookService.page(addressBookPageQueryReqDTO);
    }


    /**
     * @description: 地址簿详情
     * @author: xushuaihang
     * @Date: 2024/8/19 9:01
     * @param:
     * @param id
     * @return: com.jzo2o.customer.model.domain.AddressBook
    **/
    @GetMapping("/{id}")
    @ApiOperation("地址簿详情接口")
    public AddressBook getAddressById(@PathVariable("id")Long id){

       return addressBookService.getById(id);
    }


    /**
     * @description:地址簿修改接口
     * @author: xushuaihang
     * @Date: 2024/8/19 9:01
     * @param:
     * @param id
     * @param addressBookUpsertReqDTO
     * @return: void
    **/
    @PutMapping("/{id}")
    @ApiOperation("地址簿修改接口")
    public void updateAddress(
            @PathVariable("id") Long id,
            @RequestBody AddressBookUpsertReqDTO addressBookUpsertReqDTO){

        addressBookService.updateAddress(id,addressBookUpsertReqDTO);

    }

    /**
     * @description: 删除
     * @author: xushuaihang
     * @Date: 2024/8/19 19:31
     * @param:
     * @param ids
     * @return: void
    **/
    @DeleteMapping("/batch")
    public void batchDel(@RequestBody String[] ids){

        addressBookService.batchDel(ids);

//        addressBookService.removeByIds(ids);
    }


    /**
     * @description:  设置默认地址
     * @author: xushuaihang
     * @Date: 2024/8/19 19:31
     * @param:
     * @param flag
     * @param id
     * @return: void
    **/
    @PutMapping("/default")
    public void defaultAddr(@RequestParam Long id,@RequestParam Integer flag){

        addressBookService.defaultAddr(flag,id);
    }


    @GetMapping("/defaultAddress")
    public AddressBook defaultAddress(){

       return addressBookService.defaultAddress();
    }


}
